import Vue from 'vue';
import VueRouter from 'vue-router';
import Index from '../views/Index.vue';
import Home from '../views/Home.vue';
import Store from '../store';
import WorkBench from '../views/works/WorkDetail.vue';
import JobInfo from '../views/works/JobInfo.vue';
import WorkResult from '../views/works/WorkResult.vue';
import TranListNum from '../views/works/TranListNum.vue';
import HaveDone from '../views/works/HaveDone.vue';
import BankBillList from '../views/bankBill/BankBillList.vue';
import AccountList from '../views/bankBill/AccountList.vue';
import BillInfoEdit from '../views/bankBill/BillInfoEdit.vue';
import BillInfoShow from '../views/bankBill/BillInfoShow.vue';
import AddBillInfo from '../views/bankBill/AddBillInfo.vue';

Vue.use(VueRouter);

const routes = [
  {
    path: '/',
    name: 'Index',
    component: Index
    // redirect: { name: 'ReserveAccount' }
  },
  {
    path: '/reserveAccount',
    name: 'ReserveAccount',
    meta: { title: '预约开户' },
    component: () => import(/* webpackChunkName: "openAccount" */ '../views/Home/openAccount/ReserveAccount.vue')
  },
  {
    path: '/fillAccountInfo',
    name: 'FillAccountInfo',
    meta: { title: '填写开户信息' },
    component: () => import(/* webpackChunkName: "openAccount" */ '../views/Home/openAccount/FillAccountInfo.vue')
  },
  {
    path: '/authInformation',
    name: 'AuthInformation',
    meta: { title: '认证材料上传' },
    component: () => import(/* webpackChunkName: "openAccount" */ '../views/Home/openAccount/AuthInformation.vue')
  },
  {
    path: '/authVideo',
    name: 'AuthVideo',
    meta: { title: '认证视频上传' },
    component: () => import('../views/Home/openAccount/AuthVideo.vue')
  },
  {
    path: '/home',
    name: 'Home',
    component: Home,
    children: [
      {
        path: '/accountInquiry',
        name: 'AccountInquiry',
        meta: { title: '账户查询' },
        component: () => import('../views/Home/AccountInquiry.vue')
      },
      {
        path: '/depositSummary',
        name: 'DepositSummary',
        meta: { title: '活期存款' },
        component: () => import('../views/Home/DepositSummary.vue')
      },
      {
        path: '/depositList',
        name: 'DepositList',
        meta: { title: '明细查询' },
        component: () => import('../views/Home/DepositList.vue')
      },
      {
        path: '/depositDetail',
        name: 'DepositDetail',
        meta: { title: '转账明细' },
        component: () => import('../views/Home/DepositDetail.vue')
      },
      {
        path: '/transfer',
        name: 'Transfer',
        meta: { title: '转账汇款' },
        component: () => import(/* webpackChunkName: "transfer" */ '../views/Home/Transfer.vue')
      },
      {
        path: '/transferConfirm/:type',
        name: 'TransferConfirm',
        meta: { title: '转账信息确认' },
        component: () => import('../views/Home/TransferConfirm.vue')
      },
      {
        path: '/timeDeposit',
        name: 'TimeDeposit',
        meta: { title: '定期产品', auth: true },
        component: () => import(/* webpackChunkName: "transfer" */ '../views/Home/TimeDeposit.vue')
      },
      {
        path: '/timeDepositConfirm',
        name: 'TimeDepositConfirm',
        meta: { title: '定期产品确认' },
        component: () => import(/* webpackChunkName: "transfer" */ '../views/Home/TimeDepositConfirm.vue')
      },
      {
        path: '/transferOut',
        name: 'TransferOut',
        meta: { title: '填写信息' },
        component: () => import('../views/TransferOut.vue')
      },
      {
        path: '/investment',
        name: 'Investment',
        meta: { title: '投资理财' },
        component: () => import('../views/Investment.vue')
      },
      {
        path: '/assets',
        name: 'Assets',
        meta: { title: '我的资产' },
        component: () => import('../views/Assets.vue')
      }
      // {
      //   path: '/reserveAccount',
      //   name: 'ReserveAccount',
      //   meta: { title: '预约开户' },
      //   component: () => import('../views/Home/openAccount/ReserveAccount.vue')
      // },
      // {
      //   path: '/fillAccountInfo',
      //   name: 'FillAccountInfo',
      //   meta: { title: '填写开户信息' },
      //   component: () => import('../views/Home/openAccount/FillAccountInfo.vue')
      // },
      // {
      //   path: '/authInformation',
      //   name: 'AuthInformation',
      //   meta: { title: '认证材料上传' },
      //   component: () => import('../views/Home/openAccount/AuthInformation.vue')
      // },
      // {
      //   path: '/authVideo',
      //   name: 'AuthVideo',
      //   meta: { title: '认证视频上传' },
      //   component: () => import('../views/Home/openAccount/AuthVideo.vue')
      // }
    ]
  },
  {
    path: '/workBench',
    name: 'WorkBench',
    component: WorkBench,
    meta: {
      keepAlive: true, // 需要被缓存
      isBack: false
    }
  },
  {
    path: '/jobInfo',
    name: 'jobInfo',
    component: JobInfo
  },
  {
    path: '/workResult',
    name: 'workResult',
    component: WorkResult
  },
  {
    path: '/TranListNum',
    name: 'TranListNum',
    component: TranListNum
  },
  {
    path: '/HaveDone',
    name: 'HaveDone',
    component: HaveDone,
    meta: {
      keepAlive: true // 需要被缓存
    }
  },
  {
    path: '/BankBillList',
    name: 'BankBillList',
    component: BankBillList
  },
  {
    path: '/AccountList',
    name: 'AccountList',
    component: AccountList
  },
  {
    path: '/BillInfoEdit',
    name: 'BillInfoEdit',
    component: BillInfoEdit
  },
  {
    path: '/BillInfoShow',
    name: 'BillInfoShow',
    component: BillInfoShow
  },
  {
    path: '/AddBillInfo',
    name: 'AddBillInfo',
    component: AddBillInfo
  }
];

const router = new VueRouter({
  routes
});

router.beforeEach((to, from, next) => {
  if (to.meta.auth && !Store.state.isLogin) {
    Store.state.needLogin = true;
    next('/');
  }
  const menu = ['Index', 'Home', 'TranListNum', 'Me'];
  if (menu.includes(to.name)) {
    Store.state.showMenu = true;
  } else {
    Store.state.showMenu = false;
  }
  next();
});

export default router;
